package com.xinchen.quartz.core.test.SimpleDemo;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * Description：
 *
 * @author Xin Chen
 * @version 1.0
 * @date 2016/12/14 14:49
 * @see 2016/12/14 14:49 Created
 ****************************************/
public class Demo {
    public static void scheduler() throws SchedulerException {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();
        scheduler.start();

        // define the job and tie it to our MyJob class
        JobDetail job = newJob(MyJob.class)
                .withIdentity("job1","group1")
                .build();
        // Trigger the job to run now, and then repeat every 40 seconds
        Trigger trigger = newTrigger()
                .withIdentity("trigger1","group1")
                .startNow()
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(1)
                        .repeatForever())
                .build();
        // Tell quartz to schedule the job using our trigger
        scheduler.scheduleJob(job,trigger);
    }

    public static void main(String[] args) {
        try {
            scheduler();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
